//
//  ByFootBallTypeView.m
//  caipiao_ios
//
//  Created by mc on 2018/7/20.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByFootBallTypeView.h"

@implementation ByFootBallTypeView

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
    }
    return self;
}

- (void)setType:(NSInteger)type{
    _type = type;
}

- (void)setTypeArray:(NSMutableArray *)typeArray{
    _typeArray = typeArray;
    CGFloat top = 10;
    CGFloat height = 35;
    CGFloat left = 15;
    CGFloat width = (SCREEN_WIDTH - left * 4) / 3;
    for (int i = 0; i < _typeArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:button];
        button.frame = CGRectMake(left + (width + left) * (i % 3), top + (height + left) * (i / 3), width, height);
        [button setTitle:_typeArray[i] forState:UIControlStateNormal];
        button.layer.cornerRadius = 5;
        button.titleLabel.font = FONT(14);
        [button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 100 + i;
        if (i == _type) {
            
            button.backgroundColor = BY_THEME_COLOR;
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            
        }else{
            
            button.layer.borderColor = BY_THEME_COLOR.CGColor;
            button.layer.borderWidth = 1;
            button.backgroundColor = [UIColor whiteColor];
            [button setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
            
        }
    }
}

- (void)btnAction:(UIButton *)btn{
    if (self.indexAtView) {
        self.indexAtView(btn.tag - 100);
    }
    
}


@end
